  import { fileURLToPath, URL } from 'node:url'
import path from 'path'
import { defineConfig } from 'vite'
import vue from '@vitejs/plugin-vue'
import vueJsx from '@vitejs/plugin-vue-jsx'

import AutoImport from 'unplugin-auto-import/vite'
import Components from 'unplugin-vue-components/vite'
import { ElementPlusResolver } from 'unplugin-vue-components/resolvers'

import { createSvgIconsPlugin } from 'vite-plugin-svg-icons'
import legacy from '@vitejs/plugin-legacy'


// https://vitejs.dev/config/
export default defineConfig({
  base:'./',
  css: {
    preprocessorOptions: {
      scss: {
        additionalData: '@use "@/styles/variables.scss" as *;@use "@/styles/mixins.scss" as *;'
      }
    }
  },
  build: {
    target: 'es2015',
    minify:'terser'
  },
  plugins: [
    vue(),
    vueJsx(),
    legacy({
      targets:['defaults','chrome >= 72']
    }),
    AutoImport({
      resolvers: [ElementPlusResolver()],
      eslintrc: {
        enabled: true
      },
    }),
    Components({
      resolvers: [ElementPlusResolver()],
    }),
    createSvgIconsPlugin({
			iconDirs: [path.resolve(__dirname, 'src/assets/svg')],
			symbolId: 'icon-[name]',
			inject: 'body-first',
			// customDomId: '__svg__icons__dom__',
		}),
  ],
  server: {
    host:'127.0.0.1',
    port: 2022
  },
  preview: {
    host:'127.0.0.1',
    port: 2022
  },
  resolve: {
    alias: {
      '@': fileURLToPath(new URL('./src', import.meta.url))
    }
  }
})
